package com.cy.controller;


import com.cy.bfzcommons.pojo.Logs;
import com.cy.bfzcommons.service.LogsService;
import com.cy.bfzcommons.web.util.JsonResult;
import com.cy.bfzcommons.web.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logs")
public class LogsController {
    @Autowired
    private LogsService logsService;

    /**
     * 查询所有日志
     * @return
     */
    @GetMapping("/selectLogs")
    public JsonResult selectLogs(){
        List<Logs> list =  logsService.selectLogs();
        return  JsonResult.ok( PageUtil.startpage().doSelectPageInfo(()->
                logsService.selectLogs()));
    }

    /**
     * 新增日志
     * @param logs
     * @return
     */
    @PostMapping("/insertLogs")
    public JsonResult insertLogs(@ApiParam(name="logs",value="日志信息",required=true)@PathVariable Logs logs){
        logsService.insertLogs(logs);
        return JsonResult.ok();
    }


    /**
     * 清空日志
     * @return
     */
    @DeleteMapping("/deleteLogs")
    public JsonResult deleteLogs(){

        return JsonResult.ok("删除了"+logsService.deleteLogs()+"数据");
    }

    /**
     * 模糊查询
     * @return
     */
    @GetMapping("/selectLike")
    public JsonResult selectLike(@ApiParam(name="username",value="用户名",required=true)String username,
                                 @ApiParam(name="operation",value="操作行为",required=true)String operation,
                                 @ApiParam(name="created",value="创建时间",required=true) String created){
        //System.out.println(created);
       // List<Logs> list =  logsService.selectLike(username,operation,created);

        return JsonResult.ok(PageUtil.startpage().doSelectPageInfo(()->
                logsService.selectLike(username,operation,created)));
    }


}
